import pygame
import numpy as np

# 初始化pygame
pygame.init()

# 设置屏幕大小和标题
screen_width = 800
screen_height = 600
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption("Particle Motion")

# 设置颜色
white = (255, 255, 255)
black = (0, 0, 0)

# 生成粒子位置和速度的数组
num_particles = 100
positions = np.zeros((3, num_particles))
velocities = np.random.rand(3, num_particles)

# 初始化时间变量
time = 0
dt = 0.1  # 时间步长

# 主循环
running = True
while running:
    # 处理事件
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

            # 更新粒子的位置
    for i in range(num_particles):
        positions[:, i] += velocities[:, i] * dt

        # 清屏
    screen.fill(white)

    # 绘制粒子位置
    for i in range(num_particles):
        pygame.draw.circle(screen, black, (int(positions[0, i]), int(positions[1, i])), 5)

    #     # 绘制运动路径
    # for i in range(num_particles - 1):
    #     pygame.draw.line(screen, black, (int(positions[0, i]), int(positions[1, i])),
    #                      (int(positions[0, i + 1]), int(positions[1, i + 1])), 2)

    # 更新屏幕显示
    pygame.display.flip()
    time += dt

# 退出pygame
pygame.quit()